var arr = [1, [2, [3, 4]]]  // [1, 2, 3, 4]

var newArr = arr.flat(Infinity)

console.log(newArr);